package com.cy.controller;

import com.cy.pojo.JsonResult;
import com.cy.pojo.User;
import com.cy.service.UserSerice;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * @author cy
 */
@RestController
@RequestMapping("/user")
@Api(value = "用户管理类", tags = {"用户访问接口"})
public class UserController {
    @Autowired
    private UserSerice userSerice;

    @GetMapping("/getUser/{id}")
    @ApiOperation("根据id查询用户")
    @ApiImplicitParam(name = "id", value = "用户id", dataType = "long", paramType = "path", required = true)
    public JsonResult getUser(@PathVariable("id") Integer id) {
        return new JsonResult(userSerice.select(id));
    }

    @PostMapping("/addUser")
    @ApiOperation("添加用户")
    @ApiImplicitParam(paramType = "query", name = "User-add", value = "用户", required = true)
    public String addUser(@Valid @RequestBody User user) {
        userSerice.addUser(user);
        return "save OK";
    }


}
